﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace LanguageStudy
{
    public partial class WordsListView : UserControl
    {
        private ArrayList m_alWords = new ArrayList();

        public WordsListView()
        {
            InitializeComponent();
        }

        public void SetWords(ArrayList alWords)
        {
            if (alWords == null)
                return;

            this.lvWords.Clear();
            m_alWords.Clear();

            for (int _i = 0; _i < alWords.Count; _i++)
            {
                lvWords.Items.Add(new ListViewItem(alWords[_i].ToString(), _i));
                m_alWords.Add(alWords[_i]);
            }
        }

        public void Clear()
        {
            this.lvWords.Clear();
        }

        private void lvWords_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lvWords.SelectedItems.Count == 0)
                return;

            Word _word = (Word)m_alWords[lvWords.SelectedItems[0].ImageIndex];

            this.lblInfo.Text =
                _word.m_strWord + " " + _word.m_strPhonetic;

            for(int _i = 0; _i < _word.m_alMeanings.Count; _i++)
            {
                this.lblInfo.Text += "\n" + _word.m_alMeanings[_i].ToString();
            }
        }
    }
}
